from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup
import sys
import re

def getBs(url):
    try:
        html = urlopen(url)
    except HTTPError as e:
        print(e)
        return None
    try:
        bsObject = BeautifulSoup(html, "html.parser")
    except AttributeError as e:
        return None
    return bsObject

bsObj = getBs("http://en.wikipedia.org/wiki/Kevin_Bacon")
for link in bsObj.find("div",{"id":"bodyContent"}).findAll("a",href=re.compile("^(/wiki/)((?!:).)*$")):
    if 'href' in link.attrs:
        print(link.attrs['href'])